﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SingletonPattern
{
    /// <summary>
    /// 饿汉模式
    /// </summary>
    public class EagerSingleton
    {
        // 私有静态只读实例化对象
        private static readonly EagerSingleton _Instance = new EagerSingleton();
        // 设置私有静态构造函数
        private EagerSingleton() { }
        // 公开静态访问该类实例对象方法
        public static EagerSingleton GetInstance() => _Instance;

        //多线程环境下测试
        public string Say() => "SayHi，EagerSingleton！";
    }
}
